package Gui;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import controller.DealControl;
import controller.MarketingTemplateControl;
import controller.ProductControl;


import Client_Server.ClientConsole;
import Entity.Deal;
import Entity.Product;

import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.SwingConstants;

// TODO: Auto-generated Javadoc
/**
 * The Class ProdMenu.
 */
public class ProdMenu extends JPanel {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -6400283674228776823L;
	
	/** The back button. */
	public static JButton backButton = new JButton("Back");
	
	/** The text field. */
	static JTextField textField;
	
	/** The text field_2. */
	static JTextField textField_2;
	
	/** The text field_5. */
	static JTextField textField_5 = new JTextField();
	
	/** The text field_6. */
	static JTextField textField_6;
	
	/** The confirmation lable. */
	public static JLabel confirmationLable=null;
	
	/** The pc. */
	public static ProductControl pc=new ProductControl();
	
	/** The prd. */
	private Product prd=null;
	
	/** The text area. */
	static JTextArea textArea = new JTextArea();
	
	/** The text area_1. */
	static JTextArea textArea_1 = new JTextArea();
	
	/** The text area_2. */
	static JTextArea textArea_2 = new JTextArea();
	
	/** The combo box. */
	private JComboBox<?> comboBox = null;
	
	/** The combo box_1. */
	private JComboBox<?> comboBox_1 = null;
	
	/** The combo box_2. */
	private JComboBox<?> comboBox_2 = null;
	
	/** The btn new button_3. */
	static JButton btnNewButton_3 = new JButton("Remove Product");
	
	/**
	 * Instantiates a new prod menu.
	 */
	public ProdMenu() {
			super();
			viewProdMenu();
	}

	/**
	 * View prod menu.
	 */
	private void viewProdMenu() {
		MarketingDirectorGui.WelcomeLabel.setVisible(false);
		this.setSize( 1500,765  ); //set Frame size
		this.setLayout(null); //set layout
		this.setBackground(Color.LIGHT_GRAY); 
		backButton.setBounds(54, 596, 142, 29);   //set button's size and location
		add(backButton); 
		
		final JComboBox<String> comboBox = new JComboBox<String>();
		comboBox.setBounds(162, 218, 86, 20);
		comboBox.addItem("Cutlery");
		comboBox.addItem("Disposable Cutlery");
		comboBox.getSelectedItem();
		add(comboBox);
		
		final JComboBox<String> comboBox_1 = new JComboBox<String>();
		comboBox_1.setBounds(162, 255, 86, 20);
		comboBox_1.addItem("Kitchen");
		comboBox_1.addItem("crockery");
		comboBox_1.addItem("Picnic");
		add(comboBox_1);
		
		final JComboBox<String> comboBox_2 = new JComboBox<String>();
		comboBox_2.setBounds(162, 142, 86, 20);
		comboBox_2.addItem("White");
		comboBox_2.addItem("Black");
		comboBox_2.addItem("Blue");
		comboBox_2.addItem("Green");
		comboBox_2.addItem("Red");
		comboBox_2.addItem("Yellow");
		comboBox_2.addItem("Pink");
		comboBox_2.addItem("Brown");
		comboBox_2.addItem("Purple");
		comboBox_2.addItem("Orange");
		comboBox_2.addItem("Grey");
		add(comboBox_2);
		
		JButton btnNewButton_1 = new JButton("Add Product");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				prd=new Product(textField.getText(),
						(String)comboBox_2.getSelectedItem(),
								textField_2.getText(),
									(String)comboBox_1.getSelectedItem(),
										(String)comboBox.getSelectedItem(),
										textField_5.getText());
				
				if(!pc.ProdCheckFields(prd)){
					textArea_1.setText("Pleae Fill All The Fields !!");
					textArea_1.setVisible(true);
				
				}
				else if(!pc.CheckNewPrice(prd.getPrice())){
					textArea_1.setText("Invalid Price !! Try Again..");
					textArea_1.setVisible(true);

				}
				else {
					textArea_1.setText("");
					pc.AddProduct(prd);
					textArea.setVisible(true);
					textArea_2.setVisible(true);
					textArea_1.setVisible(true);
				}
			
			}});
		btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 13));
		btnNewButton_1.setBounds(54, 348, 142, 29);
		add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("Search Product");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(! pc.checkProdId(textField_6.getText()) ){
					textArea.setText("Pleae Fill The Search Field !!");
					textArea.setVisible(true);
					textArea_2.setVisible(true);
					textArea_1.setVisible(true);
				}
				else {
					textArea.setText("");
					pc.searcProduct(textField_6.getText());
					textArea.setVisible(true);

				}
			}});
		btnNewButton_2.setFont(new Font("Tahoma", Font.PLAIN, 13));
		btnNewButton_2.setBounds(401, 137, 142, 29);
		add(btnNewButton_2);
		
		JLabel lblAddNewProduct = new JLabel("Add New Product");
		lblAddNewProduct.setVerticalAlignment(SwingConstants.BOTTOM);
		lblAddNewProduct.setHorizontalAlignment(SwingConstants.LEFT);
		lblAddNewProduct.setForeground(new Color(128, 0, 0));
		lblAddNewProduct.setBackground(Color.WHITE);
		lblAddNewProduct.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblAddNewProduct.setBounds(54, 62, 164, 34);
		add(lblAddNewProduct);
		
		JLabel lblNewLabel = new JLabel("Product Number :");
		lblNewLabel.setForeground(new Color(75, 0, 130));
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(40, 110, 111, 21);
		add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Color :");
		lblNewLabel_1.setForeground(new Color(75, 0, 130));
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(54, 142, 98, 21);
		add(lblNewLabel_1);
		
		JLabel lblSize = new JLabel("Size :");
		lblSize.setForeground(new Color(75, 0, 130));
		lblSize.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSize.setBounds(54, 180, 98, 21);
		add(lblSize);
		
		JLabel lblType = new JLabel("Type :");
		lblType.setForeground(new Color(75, 0, 130));
		lblType.setHorizontalAlignment(SwingConstants.RIGHT);
		lblType.setBounds(54, 218, 98, 21);
		add(lblType);
		
		JLabel lblSector = new JLabel("Sector :");
		lblSector.setForeground(new Color(75, 0, 130));
		lblSector.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSector.setBounds(54, 255, 98, 21);
		add(lblSector);
		
		JLabel lblPrice = new JLabel("Price :");
		lblPrice.setForeground(new Color(75, 0, 130));
		lblPrice.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPrice.setBounds(54, 293, 98, 21);
		add(lblPrice);
		
		textField = new JTextField();
		textField.setBounds(162, 110, 86, 20);
		add(textField);
		textField.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(162, 180, 86, 20);
		add(textField_2);
		
		textField_5.setColumns(10);
		textField_5.setBounds(162, 293, 86, 20);
		add(textField_5);
		
		JLabel lblEnterProductNumber = new JLabel("Enter Product Number To Search");
		lblEnterProductNumber.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblEnterProductNumber.setHorizontalAlignment(SwingConstants.CENTER);
		lblEnterProductNumber.setForeground(new Color(75, 0, 130));
		lblEnterProductNumber.setBounds(365, 71, 218, 34);
		add(lblEnterProductNumber);
		
		textField_6 = new JTextField();
		textField_6.setBounds(426, 110, 86, 20);
		add(textField_6);
		textField_6.setColumns(10);
		
		textArea.setEditable(false);
		textArea.setBackground(Color.LIGHT_GRAY);
		textArea.setFont(new Font("Courier New", Font.BOLD, 14));
		textArea.setLineWrap(true);
		textArea.setBounds(626, 137, 407, 185);
		add(textArea);
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				textArea.setText("");
				pc.DeleteProduct(textField_6.getText());
				textArea.setVisible(true);
				textArea_2.setVisible(false);
				textArea_1.setVisible(false);
			}});

		btnNewButton_3.setForeground(Color.RED);
		btnNewButton_3.setFont(new Font("Tahoma", Font.BOLD, 13));
		btnNewButton_3.setBounds(401, 179, 142, 29);
		btnNewButton_3.setVisible(false);
		add(btnNewButton_3);
		
		textArea_1.setEditable(false);
		textArea_1.setForeground(Color.RED);
		textArea_1.setFont(new Font("Courier New", Font.BOLD, 14));
		textArea_1.setBackground(Color.LIGHT_GRAY);
		textArea_1.setBounds(54, 404, 376, 70);
		add(textArea_1);
		textArea_2.setEditable(false);
		textArea_2.setBackground(Color.LIGHT_GRAY);
		textArea_2.setFont(new Font("Courier New", Font.PLAIN, 14));
		textArea_2.setForeground(new Color(0, 128, 0));
		textArea_2.setBounds(54, 489, 376, 56);
		add(textArea_2);
		
		
		
		textArea.setVisible(false);
		textArea_1.setVisible(false);
		textArea_2.setVisible(false);
	}
}
